import QtQuick 2.6
import QtQuick.Window 2.2

import Cpp.Utility 1.0

Window {
    id: root
    visible: true

    Component.onCompleted: {
        if (Qt.platform.os === "windows") {
            x = 0
            y = 0
            height = Screen.desktopAvailableHeight
            width = 1080 * height / 1960
        }

        if (Engine.useWindowsFileSystem) {
            console.log("loading windows filesystem")

            // test platform, don't load remote resources
            Engine.addImportPath("./Qml/Base")
            Engine.qmlUsing = "windowsfs"

            body.source = "./Root.qml"
            return
        } else if (UiLoader.localLoaded) {
            console.log("loading downloaded ui")

            Engine.addImportPath("../Local/Qml/Base")
            Engine.qmlUsing = "local"

            body.source = "../Local/Qml/Root.qml"
        } else {
            console.log("loading internal ui")

            Engine.addImportPath("../Qml/Base")
            Engine.qmlUsing = "internal"

            body.source = "../Qml/Root.qml"
        }
    }

    // Loading page
    Loading {
        id: loading
        anchors.fill: parent
    }

    // Main Page
    Loader {
        id: body
        anchors.fill: parent
        visible: false
    }

    Timer {
        interval: 800
        running: true
        repeat: false
        onTriggered: {
            if (body.status === Loader.Ready) {
                body.visible = true
                loading.destroy()
            } else {
                body.statusChanged.connect(function () {
                    body.visible = true
                    loading.destroy()
                })
            }
        }
    }
}
